Component({
  data: {
    selected: 0,
    activeIndex: -1,
    list: [
      { pagePath: "/pages/challenge/index", text: "闯关" },
      { pagePath: "/pages/video/index", text: "视频" },
      { pagePath: "/pages/profile/index", text: "个人中心" }
    ]
  },
  methods: {
    switchTab(index) {
      const item = this.data.list[index];
      if (!item) return;
      wx.switchTab({ url: item.pagePath });
    },
    onTap(e) {
      const index = e.currentTarget.dataset.index;
      // unified press animation
      this.setData({ activeIndex: index });
      setTimeout(() => {
        this.setData({ activeIndex: -1 });
      }, 180);

      // navigate
      this.switchTab(index);
    },
    setSelected(index) {
      this.setData({ selected: index });
    }
  }
});


